﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Hec.TextMining;
using System.Collections.Generic;
using System.Linq;

namespace Tests
{
    [TestClass]
    public class TestSerialization
    {
         [TestMethod]
        public void Test_serializer()
        {
            var docA = new Document("texteA");
            var docB = new Document("texteB");

            var mot1 = new Hec.TextMining.KeyValuePair<string, Cell>("mot1", new Cell(2, docA));
            var mot2 = new Hec.TextMining.KeyValuePair<string, Cell>("mot2", new Cell(4, docA));
            var mot3 = new Hec.TextMining.KeyValuePair<string, Cell>("mot3", new Cell(17, docB));

            var texteA = new Hec.TextMining.KeyValuePair<Document, List<Hec.TextMining.KeyValuePair<string, Cell>>>(docA, new List<Hec.TextMining.KeyValuePair<string, Cell>>());
            texteA.Value.Add(mot1);
            texteA.Value.Add(mot2);

            var texteB = new Hec.TextMining.KeyValuePair<Document, List<Hec.TextMining.KeyValuePair<string, Cell>>>(docB, new List<Hec.TextMining.KeyValuePair<string, Cell>>());
            texteB.Value.Add(mot3);

            var test = new List<Hec.TextMining.KeyValuePair<Document, List<Hec.TextMining.KeyValuePair<string, Cell>>>>();
            test.Add(texteA);
            test.Add(texteB);

            var mySerializer = new KeyValuePairSerializer(@"\MySerializedObjects\test_cell.xml");
            mySerializer.Serialize(test);
        }

         [TestMethod]
         public void Test_deserialize_1()
         {
             var mySerializer = new KeyValuePairSerializer(@"\MySerializedObjects\test_cell.xml");
             var result = mySerializer.Deserialize();

             Assert.IsNotNull(result);
         }

        [TestMethod]
        public void Test_deserialize()
        {
            var mySerializer = new KeyValuePairSerializer(@"\MySerializedObjects\test.xml");
            var result = mySerializer.Deserialize();

            Assert.IsNotNull(result);
        }

        [TestMethod]
        public void Test_serialization_Big_vsm()
        {
            var mySerializer = new KeyValuePairSerializer(@"\MySerializedObjects\final_vsm_all.xml");

            var mySource = AppDomain.CurrentDomain.BaseDirectory.Replace(@"\Tests\bin\Debug", "") + @"\Files\";
            var mining = new TextMining(mySource);

            mining._1_enleverPonctuation();
            mining._2_enleverApostrophes();
            mining._3_enleverMotsCourts(3);
            mining._4_tronquerMotsLongs(6);
            mining._5_rawFrequency_VectorSpaceModel(-1);

            mySerializer.Serialize(mining.VSM.ToList());
        }

        [TestMethod]
        public void Test_deserialize_big_vsm()
        {
            var mySerializer = new KeyValuePairSerializer(@"\MySerializedObjects\final_vsm_all.xml");
            var result = mySerializer.Deserialize();

            Assert.IsNotNull(result);
        }

        [TestMethod]
        public void Test_serialization_take_2_docs_serialize()
        {
            var mySerializer = new KeyValuePairSerializer(@"\MySerializedObjects\test_vsm_2.xml");

            var mySource = @"\TDWI\tdwi.white.papers.library.flat";
            var mining = new TextMining(mySource);

            mining._1_enleverPonctuation();
            mining._2_enleverApostrophes();
            mining._3_enleverMotsCourts(3);
            mining._4_tronquerMotsLongs(6);
            mining._5_rawFrequency_VectorSpaceModel(1);

            mySerializer.Serialize(mining.VSM.Take(2).ToList());
        }

        [TestMethod]
        public void Test_deserialize2()
        {
            var mySerializer = new KeyValuePairSerializer(@"\MySerializedObjects\test_vsm_2.xml");
            var result = mySerializer.Deserialize();

            Assert.IsNotNull(result);
        }

    }
}
